﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TrayMes
{
    [AttributeUsage(AttributeTargets.All)]
    public class SocketStateAttribute : Attribute
    {
        public static readonly SocketStateAttribute Default = new SocketStateAttribute();
        private string context;
        private string foreground;
        private string background;
        private string message;
        public virtual string Context => ContextValue;
        public virtual string Foreground => ForegroundValue;
        public virtual string Background => BackgroundValue;
        public virtual string Message => MessageValue;

        protected string ContextValue
        {
            get
            {
                return context;
            }
            set
            {
                context = value;
            }
        }
        protected string ForegroundValue
        {
            get
            {
                return foreground;
            }
            set
            {
                foreground = value;
            }
        }
        protected string BackgroundValue
        {
            get
            {
                return background;
            }
            set
            {
                background = value;
            }
        }
        protected string MessageValue
        {
            get
            {
                return message;
            }
            set
            {
                message = value;
            }
        }

        public SocketStateAttribute()
            : this(string.Empty, string.Empty, string.Empty, string.Empty)
        {
        }

        public SocketStateAttribute(string context, string forcolor, string backcolor, string message)
        {
            this.context = context;
            this.foreground = forcolor;
            this.background = backcolor;
            this.message = message;
        }

        public override bool Equals(object obj)
        {
            if (obj == this)
            {
                return true;
            }

            SocketStateAttribute socketStateAttribute = obj as SocketStateAttribute;
            if (socketStateAttribute != null)
            {
                return socketStateAttribute.Context == Context &&
                    socketStateAttribute.Foreground == Context &&
                    socketStateAttribute.Background == Context &&
                    socketStateAttribute.Message == Context;
            }

            return false;
        }

        public override int GetHashCode()
        {
            return $"{Context}-{Foreground}-{Background}-{Message}".GetHashCode();
        }

        public override bool IsDefaultAttribute()
        {
            return Equals(Default);
        }
    }
}
